/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cassys.dataaccess.hibernate;

import cassys.dataaccess.DAOException;
import cassys.dataaccess.LectureDAO;
import cassys.datatransferobjects.LecturerDTO;
import cassys.datatransferobjects.ModuleDTO;
import cassys.datatransferobjects.UserDTO;
import cassys.exceptions.HibernateAccessLayerException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Priyanka
 */
public class LectureDAOImpl extends AbstractDao implements LectureDAO {

    public LectureDAOImpl(){
        super();
    }
   
    public void insertModule(ModuleDTO module,String username)
    {
         try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Updating User" + username); 
             LecturerDTO p = (LecturerDTO) super.find(LecturerDTO.class, username);
             p.addModule(module);
              super.saveOrUpdate(p);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public void insertorUpdateLecture(LecturerDTO lecturer) {
     try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Updating User" + lecturer.getUsername()); 
            super.saveOrUpdate(lecturer);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

   

    @Override
    public LecturerDTO findLecture(String userId) {
         try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Finding User" + userId);
            LecturerDTO p = (LecturerDTO) super.find(LecturerDTO.class, userId);
            return p;
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }
    
     @Override
    public LecturerDTO findLectureByName(String username) {
         try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Finding User" + username);
            LecturerDTO p = (LecturerDTO) super.findByParam(LecturerDTO.class, "lecturername", username);
            return p;
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public ArrayList<LecturerDTO> findAllLecture() {
       try {
            return (ArrayList<LecturerDTO>) super.findAll(LecturerDTO.class);
            } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
    }
@Override
    public void insertOrUpdateUser(UserDTO usr) {
           try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Updating User" + usr.getUsername()); 
            super.saveOrUpdate(usr);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public void deleteUser(UserDTO usr) {
        try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Deleting User" + usr.getUsername());
            super.delete(usr);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public UserDTO findUser(String username) {
          try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Finding User" + username);
            UserDTO p = (UserDTO) super.find(UserDTO.class, username);
            return p;
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
        
    }

    @Override
    public ArrayList<UserDTO> findAllUser() {
        try {
            return (ArrayList<UserDTO>) super.findAll(UserDTO.class);
            } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
        }
    }

    @Override
    public void deleteModule(ModuleDTO module, String username) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void updateModule(ModuleDTO module, String username) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public void deleteLecture(LecturerDTO lecturer) {
        try {
            Logger.getLogger(getClass().getName()).log(Level.INFO, "Deleting User" + lecturer.getUsername());
            super.delete(lecturer);
        } catch (Throwable t) {
            throw new HibernateAccessLayerException(t.toString());
            
        }
    }

    @Override
    public UserDTO findUserByName(String username) throws DAOException {
        throw new UnsupportedOperationException("Not supported yet.");
    }

}